package com.ssms.service.impl;

import com.ssms.mapper.EmployeeMapper;
import com.ssms.pojo.Employee;
import com.ssms.service.EmployeeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author Rui
 * @version 1.0
 * @date 2020/12/28 11:15
 */
@Service
public class EmployeeServiceImpl implements EmployeeService {

    @Autowired
    private EmployeeMapper employeeMapper;

    @Override
    public int addEmp(Employee employee) {
        return employeeMapper.insert(employee);
    }

    @Override
    public int delEmp(int id) {
        return employeeMapper.deleteByPrimaryKey(id);
    }

    @Override
    public int[] delManyEmps(int[] ids) {
        for (int id : ids) {
            employeeMapper.deleteByPrimaryKey(id);
        }
        return ids;
    }

    @Override
    public int updateEmp(Employee employee) {
        return employeeMapper.updateByPrimaryKeySelective(employee);
    }

    @Override
    public Employee findEmpById(int id) {
        return employeeMapper.selectByPrimaryKey(id);
    }

    @Override
    public List<Employee> findAllEmps() {
        return employeeMapper.selectByExample(null);
    }
}
